package com.jyx.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class Base {

	static void template(){
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		try {
			// link-poor
			Context context = new InitialContext();
			DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/y234");
			Connection con = ds.getConnection();
			// 1
			// conn = JdbcUtils.getConnection();
			// 2

			System.out.println(con);
			conn = JdbcUtilsSing.getInstance().getConnection();
			st = conn.createStatement();
			rs = st.executeQuery("select id,name,nickName from member");
			while(rs.next()){
				System.out.println(rs.getObject(1)+"\t"+rs.getObject(2));
			}
		} catch (SQLException | NamingException e) {
			e.printStackTrace();
		}finally {
			JdbcUtils.free(rs, st, conn);
		}
	}
	
}
